package com.tieunguyen.adapter;

import java.util.ArrayList;
import java.util.List;

import com.tieunguyen.beans.Category;
import com.tieunguyen.truyencuoi.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ListMenuAdapter extends BaseAdapter {

	private int[] images;
	private Context context;
	ArrayList<Category> categories;
	ViewGroup viewGroup;
	
	public ListMenuAdapter (Context context, ArrayList<Category> categories){
		this.context = context;
		this.categories = categories;
		init();
	}
	
	private void init() {
		int[] tmp = {
			R.drawable.vova, 
			R.drawable.muoitamcong,
			R.drawable.tinhyeu,
			R.drawable.dangian,
			R.drawable.taydukyche,
			R.drawable.tieulam,
			R.drawable.trangquynh,
			R.drawable.thegioi,
			R.drawable.tamquocche,
			R.drawable.giadinh,
			R.drawable.hocsinh,
			R.drawable.congnghe,
			R.drawable.congso,
			R.drawable.yhoc,
			R.drawable.giaothong,
			R.drawable.sayxin,
			R.drawable.vova,
			R.drawable.phapluat,
			R.drawable.khoahoc,
			R.drawable.danhnhan,
		};
		images = tmp;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return categories.size();
	}
	
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return categories.get(position);
	}

	@Override
	public long getItemId(int id) {
		// TODO Auto-generated method stub
		return id;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		// TODO Auto-generated method stub
		Category category = categories.get(position);
		if(convertView == null){
			LayoutInflater inflater = ((ActionBarActivity) context).getLayoutInflater();
			convertView = inflater.inflate(R.layout.list_item_menu,  viewGroup, false);
		}
		/*
		TextView title = (TextView)convertView.findViewById(R.id.title);
		ImageView imageView = (ImageView)convertView.findViewById(R.id.list_icon);
		Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.dangian);
		imageView.setImageBitmap(icon);
		title.setText(category.getName());
		*/
		
		TextView title = (TextView)convertView.findViewById(R.id.name);
		title.setText(category.getName());
		ImageView imageView = (ImageView)convertView.findViewById(R.id.icon);
		//Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.vova);
		//imageView.setImageBitmap(icon);
		imageView.setImageResource(images[position]);
		return convertView;
	}

}
